//
//  MineViewController.m
//  TerritoryShopkeeper
//
//  Created by xiaowu on 2017/11/27.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "MineViewController.h"
#import "LoginViewController.h"
#import "MineHeaderView.h"
#import "MineTableViewCell.h"
#import "OrderStatusModel.h"
#import "PersonHomeViewController.h"
#import "MineOrderViewController.h"
#import "MineRefundListViewController.h"
#import "AddressManageViewController.h"
#import "MineCollectionViewController.h"
#import "MineMessageViewController.h"
#import "SettingHomeViewController.h"
#import "OtherH5ViewController.h"
#import "WalletAndSignInViewController.h"
#import "CouponViewController.h"
#import "HomeGoodsDoubleCell.h"
#import "GoodsDetailViewController.h"
#import "WalletAndSignInModel.h"

#import "ShopcartOrderViewController.h"
#import "DYOpenShopModel.h"
#import "OpenShopIntroVC.h"
#import "DYMyShopVC.h"
#import "DYESPAuthVC.h"

@interface MineViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UIImageView *navigationImageView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) MineHeaderView *mineHeaderView;
@property (nonatomic, strong) NSMutableArray *itemArr;
@property (nonatomic, strong) NSMutableArray *tableArray;
@property (nonatomic, strong) OrderStatusModel *statusModel;
@property (nonatomic, strong) WalletAndSignInModel *walletModel;

@property (nonatomic, assign) NSInteger currentPage;

@end

@implementation MineViewController
#pragma mark - UIViewController
- (instancetype)init {
    self = [super init];
    if (self) {
        self.hidesBottomBarWhenPushed = NO;
        self.navigationItem.title = @"个人中心";
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshUI) name:ReciveRongCloudMessage object:nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.itemArr = [NSMutableArray arrayWithObjects:@{@"image":@"address",@"title":@"地址管理"},@{@"image":@"my_collection",@"title":@"我的收藏"},@{@"image":@"my_news",@"title":@"我的消息"},@{@"image":@"groom",@"title":@"我的团购"},@{@"image":@"sign", @"title":@"我的签到"}, @{@"image":@"er_shop",@"title":@"我的店铺"},@{@"image":@"mizhi",@"title":@"我的米值"}, nil];
    if ([UserInfo shareInstance].isOpen) {
        [self.itemArr addObject:@{@"image":@"finance",@"title":@"大众金融"}];
    }
    
    [self configureUI];
    [self configureHeader];
    
    [MBProgressHUD showHUDProgress:self.view animated:YES];
    [self getRecommendList];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    //[self setNavigationBarAlpha:0.0 animation:NO];
    //[self hideNavigationController];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    NSString *nickName, *description;
    if ([UserInfo shareInstance].isLogin) {
        [self getNetData];
        [self getWalletData];
        if (TextIsNotNil([UserInfo shareInstance].user.mnickname) && ![[UserInfo shareInstance].user.mnickname isEqualToString:@"未设置"]) {
            nickName = [UserInfo shareInstance].user.mnickname;
        } else {
            nickName = @"请完善信息";
        }
        if (TextIsNotNil([UserInfo shareInstance].user.mcontent) && ![[UserInfo shareInstance].user.mcontent isEqualToString:@"未设置"]) {
            description = [UserInfo shareInstance].user.mcontent;
        } else {
            description = @"个人简介";
        }
    } else {
        [self.statusModel updateDataZore];
        [self.mineHeaderView updateOrderCount:self.statusModel];
        nickName = @"请先登录";
        description = @"个人简介";
        
        self.walletModel = nil;
    }
    
    [self.mineHeaderView.headerImageView sd_setImageWithURL:GetUrl([UserInfo shareInstance].user.mimg) placeholderImage:PlaceholderImageHeader];
    [self.mineHeaderView.nickNameLabel setText:nickName];
    [self.mineHeaderView.descriptionLabel setText:description];
    
    [self refreshUI];
}
#pragma mark - 网络请求
- (void)getNetData {
    // 获取订单数量
    //[MBProgressHUD showHUDProgress:self.view animated:YES];
    [MYAFNetworking POST:URL_Get_Order_Status parameters:nil success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        NSString *code = responseObject[@"code"];
        if ([code isEqualToString:@"200"]) {
            NSArray *arr = responseObject[@"data"];
            NSMutableDictionary *statusDic = [[NSMutableDictionary alloc] init];
            for (NSInteger i = 0; i < arr.count; i++) {
                [statusDic setObject:arr[i] forKey:[NSString stringWithFormat:@"status%ld",i]];
            }
            self.statusModel = [OrderStatusModel mj_objectWithKeyValues:statusDic];
            [self.mineHeaderView updateOrderCount:self.statusModel];
        } else if (![code isEqualToString:@"204"]) {
            [MBProgressHUD showError:self.view title:responseObject[@"message"] code:code animated:YES];
        } else {
            [[UserInfo shareInstance] logout];
            [self.statusModel updateDataZore];
            [self.mineHeaderView updateOrderCount:self.statusModel];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [MBProgressHUD showError:self.view title:@"" code:@"" animated:YES];
    }];
}
- (void)getWalletData {
    [MYAFNetworking POST:URL_Get_Wallet parameters:nil success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        NSString *code = responseObject[@"code"];
        if ([code isEqualToString:@"200"]) {
            self.walletModel = [WalletAndSignInModel mj_objectWithKeyValues:responseObject[@"data"]];
            [self.tableView reloadData];
        } else if (![code isEqualToString:@"204"]) {
            [MBProgressHUD showError:self.view title:responseObject[@"message"] code:code animated:YES];
        } else {
            [[UserInfo shareInstance] logout];
            [self.statusModel updateDataZore];
            [self.mineHeaderView updateOrderCount:self.statusModel];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [MBProgressHUD showError:self.view title:@"" code:@"" animated:YES];
    }];
}
- (void)getRecommendList {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safeSetObject:@(self.currentPage) forKey:@"pageNumber"];
    [parameters safeSetObject:PageSize forKey:@"pageSize"];
    __weak typeof(self) weakSelf = self;
    [MYAFNetworking POST:URL_Get_Home_Recommend parameters:parameters success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        [weakSelf endRefreshing];
        
        NSDictionary *responseDic = responseObject;
        NSString *code = [responseDic safeStringForKey:@"code"];
        if (code && [code isEqualToString:@"200"]) {
            [weakSelf.tableView.mj_footer setHidden:YES];
            
            if ([responseDic[@"totalRow"] integerValue] > self.tableArray.count) {
                [weakSelf.tableView.mj_footer setHidden:NO];
            } else {
                [weakSelf.tableView.mj_footer setHidden:YES];
            }
            
            if (weakSelf.currentPage == 1) {
                [weakSelf.tableArray removeAllObjects];
                [weakSelf.tableView.mj_footer resetNoMoreData];
            }
            // 数据列表
            NSDictionary *data = [responseDic safeJsonObjectForKey:@"data"];
            NSArray *list = [data safeJsonObjectForKey:@"list"];
            if (list.count == 0 && weakSelf.currentPage != 1) {
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
                [weakSelf getNetFailure];
                return;
            }
            
            for (NSDictionary *modelDic in list) {
                HomeGoodsItem *item = [HomeGoodsItem mj_objectWithKeyValues:modelDic];
                [weakSelf.tableArray addObject:item];
            }
            
            [weakSelf.tableView reloadData];
        } else {
            [weakSelf getNetFailure];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        [MBProgressHUD showError:weakSelf.view title:@"" code:@"" animated:YES];
        [weakSelf endRefreshing];
        [weakSelf getNetFailure];
    }];
}
- (void)endRefreshing {
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}
- (void)getNetFailure {
    if (_currentPage != 1) {
        _currentPage--;
    }
}
#pragma mark - Method
- (void)configureUI {
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.navigationImageView setImage:[UIImage imageNamed:@"backpicture"]];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    //self.tableView.mj_insetT = 64;
    [self.tableView registerClass:[HomeGoodsDoubleCell class] forCellReuseIdentifier:@"doubleCell"];
    [self.tableView clearExtendCellLine];
    
    self.currentPage = 1;
    __block typeof(self) blockSelf = self;
    // 设置回调
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        _currentPage = 1;
        [blockSelf getRecommendList];
    }];
    // 菊花样式
    header.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    // 设置字体颜色
    // 状态文字
    header.stateLabel.textColor = [UIColor whiteColor];
    // 时间字体的颜色
    header.lastUpdatedTimeLabel.textColor = [UIColor whiteColor];
    
    // 设置刷新控件
    self.tableView.mj_header = header;
    
   
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        _currentPage++;
        [blockSelf getRecommendList];
    }];
    [self.tableView.mj_footer setHidden:YES];
    
    [self settingTableViewAdjustment:self.tableView];
}

- (void)configureHeader {
    self.headerView.frame = CGRectMake(0, 0, ScreenWidth, 165+64);
    self.mineHeaderView.frame = CGRectMake(0, 0, ScreenWidth - 30, 160);
    [self addlayer];
    [self responseBlock];
}

- (void)addlayer {
    UIView *layerView = [[UIView alloc] initWithFrame:CGRectMake(15, 64, ScreenWidth - 30, 160)];
    
    UIView *shadowView = [[UIView alloc] initWithFrame:layerView.bounds];
    shadowView.backgroundColor = [UIColor redColor];
    shadowView.layer.shadowOffset = CGSizeMake(0, 3);
    shadowView.layer.shadowColor = [UIColor redColor].CGColor;
    shadowView.layer.shadowOpacity = 0.2;
    //shadowView.layer.shadowRadius = 5.0;
    shadowView.layer.cornerRadius = 5.0;
    
    self.mineHeaderView.clipsToBounds = YES;
    self.mineHeaderView.layer.cornerRadius = 5;
    
    [layerView addSubview:shadowView];
    [layerView addSubview:self.mineHeaderView];
   
    [self.headerView addSubview:layerView];
    //添加设置按钮
    UIButton * settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [settingBtn setImage:[UIImage imageNamed:@"er_setting"] forState:UIControlStateNormal];
    settingBtn.frame = CGRectMake(ScreenWidth - 40, 30, 25, 25);
    [self.headerView addSubview:settingBtn];
    [settingBtn addTarget:self action:@selector(settingClicked) forControlEvents:UIControlEventTouchUpInside];
    
    self.tableView.tableHeaderView = self.headerView;
}

- (void)settingClicked{
    SettingHomeViewController *settingVC = [[SettingHomeViewController alloc] init];
    [self.navigationController pushViewController:settingVC animated:YES];
}

- (void)responseBlock {
    __weak typeof(self) weakSelf = self;
    self.mineHeaderView.infoBlock = ^{
        if ([weakSelf isLogin]) {
            PersonHomeViewController *phVC = [[PersonHomeViewController alloc] init];
            [weakSelf.navigationController pushViewController:phVC animated:YES];
        }
    };
    self.mineHeaderView.block = ^(NSInteger index) {
        NSLog(@"index:%ld", (long)index);
        if ([weakSelf isLogin]) {
            switch (index) {
                case 0:
                {
                    MineOrderViewController *orderVC = [[MineOrderViewController alloc] init];
                    orderVC.type = MineOrderTypeAll;
                    [weakSelf.navigationController pushViewController:orderVC animated:YES];
                    NSLog(@"全部订单");
                } break;
                case 1:
                {
                    MineOrderViewController *orderVC = [[MineOrderViewController alloc] init];
                    orderVC.type = MineOrderTypeObligation;
                    [weakSelf.navigationController pushViewController:orderVC animated:YES];
                    NSLog(@"待付款");
                } break;
                case 2:
                {
                    MineOrderViewController *orderVC = [[MineOrderViewController alloc] init];
                    orderVC.type = MineOrderTypeReceived;
                    [weakSelf.navigationController pushViewController:orderVC animated:YES];
                    NSLog(@"待收货");
                } break;
                case 3:
                {
                    MineOrderViewController *orderVC = [[MineOrderViewController alloc] init];
                    orderVC.type = MineOrderTypeEvaluation;
                    [weakSelf.navigationController pushViewController:orderVC animated:YES];
                    NSLog(@"待评价");
                } break;
                case 4:
                {
                    MineRefundListViewController *refundListVC = [[MineRefundListViewController alloc] init];
                    [weakSelf.navigationController pushViewController:refundListVC animated:YES];
                    NSLog(@"退款订单");
                } break;
                default:
                    break;
            }
        }
    };
}
- (BOOL)isLogin {
    //强制登录，只是加一层判断，如果以后不强制直接
    if (![UserInfo shareInstance].isLogin) {
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        BaseNavigationViewController *nav = [[BaseNavigationViewController alloc] initWithRootViewController:loginVC];
        [self presentViewController:nav animated:YES completion:nil];
        return NO;
    }
    return YES;
}

- (void)refreshUI {
    [self.itemArr replaceObjectAtIndex:2 withObject:@{@"image":@"my_news",@"title":@"我的消息",@"isshow":@([UserInfo shareInstance].user.showBadge)}];
    [self.tableView reloadData];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (self.tableArray.count == 0) {
        return 2;
    }
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return 1;
        case 1:
            return ceil(self.itemArr.count/4.0);
        case 2:
            return ceil(self.tableArray.count/2.0);
        default:
            return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 2) {
        HomeGoodsDoubleCell *doubleCell = [tableView dequeueReusableCellWithIdentifier:@"doubleCell" forIndexPath:indexPath];
        NSArray *arr =  [HomeGoodsDoubleCell getCellItemArr:self.tableArray withRow:indexPath.row];
        [doubleCell setValuesForCellWithItems:arr];
        
        __block typeof(self) blockSelf = self;
        doubleCell.block = ^(NSInteger index) {
            NSLog(@"%ld",(long)(indexPath.row*2+index));
            HomeGoodsItem *model = blockSelf.tableArray[indexPath.row*2+index];
            if (!model.isshelves) {
                [MBProgressHUD showError:blockSelf.view title:@"该商品已下架" code:@"" animated:YES];
                return;
            }
            GoodsDetailViewController *goodsDetailVC = [[GoodsDetailViewController alloc] init];
            goodsDetailVC.gid = model.gid;
            [blockSelf.navigationController pushViewController:goodsDetailVC animated:YES];
        };
        return doubleCell;
    }
    
    MineTableViewCell *cell = [MineTableViewCell mineTableCellWith:tableView indexPath:indexPath];
    
    switch (indexPath.section) {
        case 0:
        {
            [cell.firstBalanceLabel setText:TextIsNotNil(self.walletModel.wprice)?self.walletModel.wprice:@"0.00"];
            [cell.firstIntegralLabel setText:TextIsNotNil([UserInfo shareInstance].user.mintegral)?[UserInfo shareInstance].user.mintegral:@"0"];
            [cell.firstCouponsLabel setText:TextIsNotNil(self.walletModel.coupon)?self.walletModel.coupon:@"0"];
        } break;
        case 1:
        {
            [cell updateSecondCellWith:self.itemArr indexPath:indexPath];
        } break;
        default:
            break;
    }
    
    cell.block = ^(MineTableClickType type) {
        if ([self isLogin]) {
            switch (type) {
                case ClickTypeCoupons:
                {
                    CouponViewController *couponVC = [[CouponViewController alloc] init];
                    couponVC.type = CouponFromTypeMine;
                    [self.navigationController pushViewController:couponVC animated:YES];
                } break;
                case ClickTypeAddress:
                {
                    AddressManageViewController *addressManageVC = [[AddressManageViewController alloc] init];
                    [self.navigationController pushViewController:addressManageVC animated:YES];
                } break;
                case ClickTypeCollection:
                {
                    MineCollectionViewController *mineCollectVC = [[MineCollectionViewController alloc] init];
                    [self.navigationController pushViewController:mineCollectVC animated:YES];
                } break;
                case ClickTypeMessage:
                {
                    [self refreshUI];
                    MineMessageViewController *messageVC = [[MineMessageViewController alloc] init];
                    [self.navigationController pushViewController:messageVC animated:YES];
                } break;
                case ClickTypeFriend:
                {
                    // 团购订单
                    MineOrderViewController *orderVC = [[MineOrderViewController alloc] init];
                    orderVC.type = MineOrderTypeAll;
                    orderVC.classType = MineOrderClassTypeGroup;
                    [self.navigationController pushViewController:orderVC animated:YES];
                } break;
                case ClickTypeSignIn:
                {
                    WalletAndSignInViewController *WSVC = [[WalletAndSignInViewController alloc] init];
                    WSVC.type = VCTypeSignIn;
                    [self.navigationController pushViewController:WSVC animated:YES];
                } break;
                case ClickTypeSetting:
                {
                    [[UserInfo shareInstance] updateUserInterfaceModel:^(BOOL success) {
                        if ([[UserInfo shareInstance].user.sxid isEqualToString:@"0"]) { //未开店,未开店先验证
                            DYESPAuthVC * vc = [[DYESPAuthVC alloc] init];
                            vc.authType = 2;
                            [self.navigationController pushViewController:vc animated:YES];
                            
//                            OpenShopIntroVC * vc = [NSClassFromString(@"OpenShopIntroVC") new];
//                            vc.type = 0;
//                            [self.navigationController pushViewController:vc animated:YES];
                        }else{
                            [self clickedShop];
                        }
                    }];
                    
                   
                } break;
                case ClickTypeSpecial:
                {
                    if ([self checkOpen]) {
                        OtherH5ViewController *dzjrVC = [[OtherH5ViewController alloc] init];
                        dzjrVC.title = @"大众金融";
                        dzjrVC.url = @"http://wx.dztcjzg.com";
                        [self.navigationController pushViewController:dzjrVC animated:YES];
                    }
                } break;
                case ClickTypeMiZhi:
                {
//                    if ([UserInfo shareInstance].user.msource.integerValue != 2) {
//                        [MBProgressHUD myShowHUDAddedTo:self.view labelText:@"对不起，您不是ESP用户" animated:YES];
//                        return;
//                    }
                    WalletAndSignInViewController *WSVC = [[WalletAndSignInViewController alloc] init];
                    WSVC.type = VCTypeMiZhi;
                    [self.navigationController pushViewController:WSVC animated:YES];
                } break;
                default:
                    break;
            }
        }
    };
    
    return cell;
}

//hdy2期点击我的店铺
- (void)clickedShop{
    __weak typeof(self) weakSelf = self;
    NSString * uid = [UserInfo shareInstance].user.mid;
//    uid = @"304";
    [MBProgressHUD showHUDProgress:self.view animated:YES];
    [MYAFNetworking POST:@"api2/useropenshopfor" parameters:@{@"uid":uid} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        //根据响应，来判断是否是已已经开店
        NSString * code = [responseObject safeStringForKey:@"code"];
        if (![code isEqualToString:@"200"]) {
            [MBProgressHUD showError:weakSelf.view title:nil code:code animated:YES];
            return;
        }
        DYOpenShopModel * model = [DYOpenShopModel mj_objectWithKeyValues:[responseObject safeObjectForKey:@"data"]];
        if ([model.status isEqualToString:@"0"]) { //待审核
            [MBProgressHUD showError:weakSelf.view title:@"正在审核中" code:@"" animated:YES];
        }else if ([model.status isEqualToString:@"1"]){ //审核已通过
            //跳转到店铺主页
            DYMyShopVC * vc = [[DYMyShopVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.status isEqualToString:@"2"]){ //审核未通过
            OpenShopIntroVC * vc = [NSClassFromString(@"OpenShopIntroVC") new];
            vc.type = 1;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.status isEqualToString:@"3"]){ //禁用
            [MBProgressHUD showError:weakSelf.view title:@"已禁用" code:@"" animated:YES];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
    }];
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
            return 80;
        case 1:
            return 87;
        case 2:
            return [HomeGoodsDoubleCell getHeight];
        default:
            return 0;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if ([self isLogin]) {
        switch (indexPath.section) {
            case 0:
            {
                WalletAndSignInViewController *WSVC = [[WalletAndSignInViewController alloc] init];
                WSVC.type = VCTypeWallet;
                [self.navigationController pushViewController:WSVC animated:YES];
            } break;
            default:
                break;
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    } else if (section == 1) {
        return 10;
    }
    return 20;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    } else if (section == 1) {
        return 10;
    }
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section {
    return 1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return nil;
    } else if (section == 1) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
        [view setBackgroundColor:[UIColor backgroundColor]];
        return view;
    } else {
        UIView *view = [UIView new];
        view.backgroundColor = [UIColor backgroundColor];
        UILabel *label = [[UILabel alloc] init];
        
        label.textAlignment = NSTextAlignmentCenter;
        label.frame = CGRectMake(0, 10, 100, 30);
        label.textColor = [UIColor whiteColor];
        
        [label setGradientHorizontal:@[[UIColor colorWithHex:0xFFB965 alpha:1.0],[UIColor colorWithHex:0xFF3B3B alpha:1.0]]];
        [label addRoundedCorners:(UIRectCornerTopRight | UIRectCornerBottomRight) withRadii:CGSizeMake(100, 30)];
        [label setGradientHorizontal:@[[UIColor colorWithHex:0x65CCFF alpha:1.0],[UIColor colorWithHex:0x3BABFF alpha:1.0]]];
        label.text = @"为你推荐";
        [view addSubview:label];
        
        return view;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 1)];
    [view setBackgroundColor:[UIColor whiteColor]];
    return view;
}
#pragma mark - Getters
- (NSMutableArray *)tableArray {
    if (!_tableArray) {
        _tableArray = [[NSMutableArray alloc] init];
    }
    return _tableArray;
}

- (MineHeaderView *)mineHeaderView {
    if (!_mineHeaderView) {
        _mineHeaderView = [[MineHeaderView alloc] init];
    }
    return _mineHeaderView;
}

- (UIView *)headerView {
    if (!_headerView) {
        _headerView = [[UIView alloc] init];
    }
    return _headerView;
}

- (OrderStatusModel *)statusModel {
    if (!_statusModel) {
        _statusModel = [[OrderStatusModel alloc] init];
    }
    return _statusModel;
}

#pragma mark -
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:ReciveRongCloudMessage object:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
